﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using Cinchoo.Core.IO;
using System.Data.SqlClient;

namespace Cinchoo.Core.ETL
{
    [XmlRoot("sqlClientCommandTask")]
    public class ChoETLSqlClientCommandTaskDef : ChoETLTaskDef
    {
        [ChoETLTaskDefPropertyInfo("CONNECTION_STRING", IsRequired = true)]
        [XmlAttribute("connectionString")]
        public string ConnectionString;

        [ChoETLTaskDefPropertyInfo("SQL", IsRequired = true)]
        [XmlAttribute("sql")]
        public string Sql;

        protected override ChoETLTask Construct(ChoETLWorkflow workflow)
        {
            ChoGuard.ArgumentNotNullOrEmpty(ConnectionString, "ConnectionString");
            ChoGuard.ArgumentNotNullOrEmpty(Sql, "Sql");

            SqlConnection connection = new SqlConnection(ConnectionString);

            return new ChoETLSqlClientCommandTask(connection, Sql);
        }
    }
}
